package com.es.servlet;
/**
 * 描述:
 * es-jsp-
 *
 * @author Derek
 * 创建时间：2022-04-25 10:24
 */

import com.es.bean.Student;
import com.es.service.StudentService;
import com.es.service.impl.StudentServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.util.List;

@WebServlet(name = "ListServlet", value = "/list")
public class ListServlet extends HttpServlet {

    StudentService service = new StudentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //查询到的数据到前端？

        List<Student> list = service.list();
        //
        list.forEach(System.out::println);
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head><title>学生列表</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<div style='width:500px;margin:0px auto;'>");
        out.println("<table>");
        out.println("<tr><td>学号</td><td>姓名</td><td>年龄</td><td>性别</td><td>地址</td><td>电话</td></tr>");
        for(Student s: list){
            out.println("<tr><td>"+s.getId()+"</td><td>"+s.getName()+"</td><td>"+s.getAge()+"</td><td>"+s.getSex()+"</td><td>"+s.getAddress()+"</td><td>"+s.getTelephone()+"</td></tr>");
        }
        out.println("</table>");
        out.println("</div>");
        out.println("<body>");
        out.println("</html>");
        out.flush();
    }

}
